<?php

include_once($cfgPaths['lib/dba'].'udba.o.inc.php');
  
class dbaPropertySet extends udba{
  function dbaPropertySet($dbase,$dbhost,$dbusr,$dbpass,$dbms = 'mysql'){
    udba::udba($dbase,$dbhost,$dbusr,$dbpass,$dbms);
  } 
  
  function createPropertySet($pname){
    return $this->query("insert into cat_propertyset (name) values('$pname');");
  }
    
  function getPropertySetsArray(&$result, $ordered = false){
    if ($ordered){
      $orderStr = ' order by name';
    }
    $check = $this->query("select * from cat_propertyset$orderStr;");
    if ($check) {$result = $this->fetch_rows_array();}
    return $check;
  }

  
  function getPropertyTypesArray(&$result, $ordered = false){
    if ($ordered){
      $orderStr = ' order by type_descr';
    }
    $check = $this->query("select * from property_type$orderStr;");
    if ($check) {$result = $this->fetch_rows_array();}
    return $check;
  }

  // Alle PropertySets aus db holen
  function getPropertySets(&$result, $ordered = false){
    if ($ordered){
      $orderStr = ' order by name';
    }
    $check = $this->query("select * from cat_propertyset$orderStr;");
    if ($check){$result = $this->fetch_rows();}
    return $check;
  }
  
  // Properties eines Sets aus db holen mit set_id
  function getPSetPropertiesArray(&$result, $set_id, $ordered = false){
    if ($ordered){
      $orderStr = ' order by name';
    }
    $check = $this->query("select * from cat_propertyset_property where propertyset_id = $set_id $orderStr;");
    if ($check) {$result = $this->fetch_rows_array();}
    return $check;
  }

  // Properties eines Sets aus db holen mit set_id
  function getPSetPropertiesArrayWithTypes(&$result, $set_id, $ordered = false){
    if ($ordered){
      $orderStr = ' order by name';
    }
    $check = $this->query("select cat_propertyset_property.id,cat_propertyset_property.propertyset_id,cat_propertyset_property.name,property_type.type_descr from cat_propertyset_property,property_type where cat_propertyset_property.propertyset_id = $set_id AND cat_propertyset_property.property_type_id = property_type.id $orderStr;");
    if ($check) {$result = $this->fetch_rows_array();}
    return $check;
  }
  
  function addPSetProperty($set_id,$name,$type_id){
    return $this->query("insert into cat_propertyset_property (propertyset_id,name,property_type_id) values($set_id,'$name',$type_id);");
  }

  function delPSetProperty($prop_id){
    return $this->query("delete from cat_propertyset_property where id=$prop_id;");
  }
}

?>
